package cn.iocoder.yudao.module.student.controller.app.curriculumVitaeSendRecord;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.security.core.LoginUser;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.module.member.api.curriculumVitaeSendRecord.CurriculumVitaeSendRecordApi;
import cn.iocoder.yudao.module.member.api.curriculumVitaeSendRecord.dto.*;
import cn.iocoder.yudao.module.member.api.job.dto.JobRespDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Api(tags = "管理后台 -学生端- 简历投递记录")
@RestController
@RequestMapping("/student/curriculum-vitae-send-record")
@Validated
public class StudentCurriculumVitaeSendRecordController {

    @Resource
    private CurriculumVitaeSendRecordApi curriculumVitaeSendRecordApi;

    @PostMapping("/send")
    @ApiOperation("简历投递")
    public CommonResult<Long> createCurriculumVitaeSendRecord(@Valid @RequestBody CurriculumVitaeSendRecordCreateReqDTO createReqVO) {
        return success(curriculumVitaeSendRecordApi.sendCurriculumVitaeSendRecord(createReqVO));
    }

    @PostMapping("/page")
    @ApiOperation("获得简历投递记录分页")
    public CommonResult<PageResult<CurriculumVitaeSendRecordRespJobDTO>> checkResumeFromJob(@Valid @RequestBody CurriculumVitaeSendRecordPageReqDTO pageVO) throws Exception{
        pageVO.setStudentId(SecurityFrameworkUtils.getLoginUserId());
        PageResult<CurriculumVitaeSendRecordRespJobDTO> pageResult = curriculumVitaeSendRecordApi.getpageJob(pageVO);
        return success(pageResult);
    }

    @PutMapping("/updateResume")
    @ApiOperation("修改简历投递")
    public CommonResult<Boolean> updateResume(@Valid @RequestBody CurriculumVitaeSendRecordUpdateReqDTO updateReqDTO) throws Exception{
        curriculumVitaeSendRecordApi.updateCurriculumVitaeSendRecord(updateReqDTO);
        return success(true);
    }

    @GetMapping("/isSend")
    @ApiOperation("获取当前用户是否投过该公司")
    public CommonResult<Boolean> isSend(Long jobId) {
        CurriculumVitaeSendRecordPageReqDTO pageVO=new CurriculumVitaeSendRecordPageReqDTO();
        pageVO.setJobId(jobId);
        LoginUser loginUser=SecurityFrameworkUtils.getLoginUser();
        pageVO.setStudentId(loginUser.getId());
        return success(curriculumVitaeSendRecordApi.isSend(pageVO));
    }

    @PostMapping("/noOpenCount")
    @ApiOperation("查看未处理简历邀约")
    public CommonResult<Long> noOpenCount(@Valid @RequestBody CurriculumVitaeSendRecordPageReqDTO pageVO) {
        return success(curriculumVitaeSendRecordApi.noOpenCount(pageVO));
    }

}
